package com.hyphenate.easeui.utils;

import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.hyphenate.easeui.R;


/**
 * 文件名：GlideUtils
 * 作者：miao
 * 日期：2018/5/4
 * 邮箱：604314401@qq.com
 * 描述：
 */
public class GlideUtils {
    public static void loadLocalCircleImage(Context context, int id, ImageView imageView) {
        RequestOptions options = RequestOptions.circleCropTransform()
                .placeholder(R.drawable.timg)
                .error(R.drawable.timg);
        Glide.with(context).asBitmap().load(id).apply(options).into(imageView);


//        RequestOptions options = new RequestOptions()
//                .centerCrop()
//                .circleCrop()//设置圆形
//                .placeholder(R.drawable.timg)
//                .error(R.drawable.timg)
//                .diskCacheStrategy(DiskCacheStrategy.ALL);
//        Glide.with(getContext()).load(R.drawable.ease_default_avatar).apply(options).into(holder.avatar);
    }

    public static void loadUrlCircleImage(Context context, String url, ImageView imageView) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.drawable.timg)
                .error(R.drawable.timg)
                ;
        Glide.with(context).load(url).apply(options).into(imageView);
    }

    public static void loadBlurImage(Activity context, String url, ImageView imageView) {
//        RequestOptions options = RequestOptions.circleCropTransform();
//                .placeholder(R.mipmap.icon_place_holder)
//                .error(R.mipmap.icon_place_holder);
//        Glide.with(context).load(url).apply(options).into(imageView);
//        Glide.with(context).load(url)
//                .apply(bitmapTransform(new BlurTransformation(context, 25, 3)))
//                .into(imageView);
        Glide.with(context).load(url).into(imageView);
    }

    public static void loadImage(Context context, String url, ImageView imageView) {
        RequestOptions options = new RequestOptions();
//                .placeholder(R.mipmap.icon_place_holder)
//                .error(R.mipmap.icon_place_holder);
        Glide.with(context).load(url).apply(options).into(imageView);
    }

    public static void loadImage(Context context, int id, ImageView imageView) {
        RequestOptions options = new RequestOptions();
//                .placeholder(R.mipmap.icon_place_holder)
//                .error(R.mipmap.icon_place_holder);
        Glide.with(context).load(id).apply(options).into(imageView);
    }

    public static void loadImage(Fragment context, String url, ImageView imageView) {
        RequestOptions options = new RequestOptions();
//                .placeholder(R.mipmap.icon_place_holder)
//                .error(R.mipmap.icon_place_holder);
        Glide.with(context).load(url).apply(options).into(imageView);
    }
}
